/*
 *
 */

package gui;

import client.Request;
import javax.swing.table.DefaultTableModel;


public class ViewMatches extends javax.swing.JPanel {

    public String type = null;
    public Request Client = null;

    /** Type specifies the type selected to view matches
      */
    public ViewMatches(Request view_Client, String view_type) {

        type = view_type;
        Client = view_Client;

        initComponents();
        find.setVisible(true);
        int i =0;
        String[] tokens = null;
        String s = null;


        label.setText("Please select a " + type + ":");
        Client.getInfo(type, tokens);

        //TESTING
        tokens = new String[2];
        tokens[0] = "apple";
        tokens [1] = "banana";

        for (i=0;i<tokens.length;i++)
            find.insertItemAt(tokens[i], i);

        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        find = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        table = new javax.swing.JTable();
        label = new javax.swing.JLabel();
        select = new javax.swing.JButton();

        setBackground(new java.awt.Color(43, 65, 152));

        jLabel1.setText("URL for team logo");

        jLabel2.setText("TEAM NAME");

        find.setMaximumRowCount(99999);
        find.setBounds(new java.awt.Rectangle(1, 1, 1, 1));
        find.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                findMouseClicked(evt);
            }
        });
        find.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                findActionPerformed(evt);
            }
        });

        table.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "Team 1", "Team 2", "Location", "Time", "Score", "Referee"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Object.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane1.setViewportView(table);

        label.setText("Find label");
        label.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                labelMouseClicked(evt);
            }
        });

        select.setText("select");
        select.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                selectMouseClicked(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(102, 102, 102)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(jLabel1)
                        .add(36, 36, 36)
                        .add(jLabel2))
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(label)
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                .add(select)
                                .add(find, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 166, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                        .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 521, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(340, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(120, 120, 120)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel1)
                            .add(jLabel2))
                        .add(114, 114, 114))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .addContainerGap(136, Short.MAX_VALUE)
                        .add(label)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(find, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(select)
                        .add(29, 29, 29)))
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void findActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_findActionPerformed

    private void findMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_findMouseClicked
    }

    private void createTable(){

        String[][] tokens = null;
        String s = find.getSelectedItem().toString();
        System.out.println("User selected to view " + type + s);
        int i;

        String[] col = {"Team 1", "Team 2", "Location", "Time", "Score", "Referee"};

        tokens = new String[1][6];
        for (i=0;i<6;i++)
            tokens[0][i] = "fad";

        DefaultTableModel model = new DefaultTableModel(null,col);       
        // Client.getSpecificGames(type, s, tokens);
        // for (i=0;i<tokens.length/6; i++)
        //model.insertRow(i, new Object[] {tokens[0+6*i], tokens[1+6*i], tokens[2+6*i],tokens[3+6*i], tokens[4+6*i], tokens[5+6*i]});
        table.setModel(model);

    }//GEN-LAST:event_findMouseClicked

    private void labelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_labelMouseClicked
    }//GEN-LAST:event_labelMouseClicked

    private void selectMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_selectMouseClicked

        createTable();
    }//GEN-LAST:event_selectMouseClicked


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox find;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel label;
    private javax.swing.JButton select;
    private javax.swing.JTable table;
    // End of variables declaration//GEN-END:variables

}
